﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Threading;
using TeacherLeftHand.Model;
using TeacherLeftHand.Util;


namespace CustomControl
{
    public class EllipsisTextBox : TextBox
    {

        public static readonly DependencyProperty ContentOfTmProperty = DependencyProperty.Register(
                                                "ContentOfTm", typeof(string), typeof(EllipsisTextBox));
        public string ContentOfTm
        {
            get { return (string)this.GetValue(ContentOfTmProperty); }
            set { this.SetValue(ContentOfTmProperty, value); }
        }

        public EllipsisTextBox()
            : base()
        {
            this.Loaded += new RoutedEventHandler(EllipsisTextBox_Loaded);
        }
        public EllipsisTextBox(string text)
        {
            this.Text = text;
        }


        void EllipsisTextBox_Loaded(object sender, RoutedEventArgs e)
        {
            var rtb = new RichTextBox();
            if (this.ContentOfTm != null)
            {
                rtb = (RichTextBox)XamlReader.Parse(this.ContentOfTm);
            }
            var toolTipRtb = new RichTextBox
                                 {
                                     Width = 630,
                                     MinHeight = 25,
                                     Document = (FlowDocument)Utility.CloneElement(rtb.Document),
                                     Margin = new Thickness(0, 0, 0, 5)
                                 };

            var nameTextBox = new TextBox { Text = this.Text, Margin = new Thickness(0, 5, 0, 5) };
            var dockPanel = new DockPanel();
            dockPanel.Children.Add(nameTextBox);
            DockPanel.SetDock(nameTextBox, Dock.Top);
            dockPanel.Children.Add(toolTipRtb); ;
            this.ToolTip = dockPanel;
        }
    }
}
